import unittest
import os
import time
import HTMLTestRunnerPlugins

# 1.确定用例文件路径和报告存放路径
base_path = os.path.dirname(__file__)  # 项目路径
case_path = os.path.join(base_path, 'Case')  # 用例路径
print(case_path)
report_path = os.path.join(base_path, "Report")  # 报告路径
now = time.strftime("%Y-%m-%d %H-%M-%S")  # 格式化当前时间
report_name = now + "HTMLReport.html"  # 测试报告名称
report_file_path = os.path.join(report_path, report_name)  # 测试报告文件路径
# 2.生成测试套件
suite = unittest.defaultTestLoader.discover(case_path)
# 执行测试生成报告
with open(report_file_path, "wb") as fp:
    runner = HTMLTestRunnerPlugins.HTMLTestRunner(
        stream=fp,  # 报告文件
        title="xxxx项目自动化测试报告",  # 报告描述
        description="xxx项目页面自动化测试",  # 报告描述
        tester="周霞"  # 测试人员
    )
    runner.run(suite)
